Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

isomorphic-ws

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isomorphic-ws

Isomorphic implementation of WebSocket

  • 5.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is isomorphic-ws?

The isomorphic-ws npm package provides a WebSocket client that works both in the browser and on the server (Node.js). It is designed to offer a consistent WebSocket API so that developers can write code that is agnostic to the environment in which it runs. This is particularly useful for building isomorphic JavaScript applications that can run on both the client-side and server-side without modification.

What are isomorphic-ws's main functionalities?

Creating WebSocket connections

This feature allows you to create WebSocket connections to a server. The code sample demonstrates how to establish a connection, and handle open, message, and close events.

const WebSocket = require('isomorphic-ws');

const ws = new WebSocket('ws://www.host.com/path');

ws.onopen = function () {
  console.log('WebSocket is open now.');
};

ws.onmessage = function (event) {
  console.log('Received message: ' + event.data);
};

ws.onclose = function () {
  console.log('WebSocket is closed now.');
};

Sending messages through WebSocket

This feature allows you to send messages to the server over the WebSocket connection. The code sample shows how to send a message to the server once the WebSocket connection is established and open.

const WebSocket = require('isomorphic-ws');

const ws = new WebSocket('ws://www.host.com/path');

ws.onopen = function () {
  ws.send('Hello Server!');
};

Receiving messages from WebSocket

This feature allows you to receive messages from the server over the WebSocket connection. The code sample demonstrates how to listen for messages from the server and log them to the console.

const WebSocket = require('isomorphic-ws');

const ws = new WebSocket('ws://www.host.com/path');

ws.onmessage = function (event) {
  console.log('Received message: ' + event.data);
};

Other packages similar to isomorphic-ws

Keywords

FAQs

Package last updated on 27 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc